package com.example.fw;

import org.openqa.selenium.By;

import com.example.tests.ContactData;

public class ContactHelper extends HelperBase {

	public ContactHelper(ApplicationManager manager) {
		super(manager);
	}

	public void initContactCreation() {
		click(By.linkText("add new"));		
	  }
	
	public void fillContactForm(ContactData contact) {	
			type(By.name("firstname"), contact.firstname);
			type(By.name("lastname"), contact.lastname);
			type(By.name("address"), contact.address);		
			type(By.name("home"), contact.homePhone);
			type(By.name("mobile"), contact.mobilePhone);		
			type(By.name("work"), contact.workPhone);
			type(By.name("email"), contact.mainMail);		
			type(By.name("email2"), contact.moreMail);					   
			selectByText(By.name("bday"), contact.bDay);
			selectByText(By.name("bmonth"), contact.bMonth);
			selectByText(By.name("new_group"), contact.group);	   
			type(By.name("byear"), contact.bYear);
			type(By.name("address2"), contact.moreAddress);	    
			type(By.name("phone2"), contact.morePhone);
	}
	
	public void fillContactFormModification(ContactData contact) {	
		type(By.name("firstname"), contact.firstname);
		type(By.name("lastname"), contact.lastname);
		type(By.name("address"), contact.address);		
		type(By.name("home"), contact.homePhone);
		type(By.name("mobile"), contact.mobilePhone);		
		type(By.name("work"), contact.workPhone);
		type(By.name("email"), contact.mainMail);		
		type(By.name("email2"), contact.moreMail);					   
		selectByText(By.name("bday"), contact.bDay);
		selectByText(By.name("bmonth"), contact.bMonth);
		//selectByText(By.name("new_group"), contact.group);	   
		type(By.name("byear"), contact.bYear);
		type(By.name("address2"), contact.moreAddress);	    
		type(By.name("phone2"), contact.morePhone);
}
	
	public void submitContactCreation() {		  
		click(By.name("submit"));
	  }
	
	public void submitContactDelete() {
		click(By.xpath("(//input[@name='update'])[2]"));	
	  }

	public void submitContactUpdate() {
		//click(By.name("update"));
		click(By.xpath("(//input[@name='update'])[1]"));		
	  }
	
	public void returnToHomePage() {		
		click(By.linkText("home"));
	  }
	
	public void selectContact() {
		click(By.cssSelector("img[alt=\"Edit\"]"));		
	}
}
